import instance from "./instance";

/* 通用的POST请求 */
export function doPost(url, data, config) {
  const promise = instance
    .post(url, data, config)
    .catch((err) => console.log("err=", err));
  return promise;
}

/* 通用的GET请求 */
export function doGet(url, data, config, defaultInstance = instance) {
  // doGet("/api/movie/playings",{page:5,pagesize:10})
  // /api/movie/playings?page=5&pagesize=10

  if (data) {
    const p = new URLSearchParams();
    for (let key in data) {
      p.append(key, data[key]);
    }
    url += `?${p.toString()}`;
  }

  return defaultInstance
    .get(url, config)
    .catch((err) => console.log("err=", err));
}
